#include "FileEvent.h"

namespace events {


void FileEvent::saveToStream(std::ostream &os) const {
	os.write(reinterpret_cast<const char*>(&_fetype), sizeof(_fetype));
	_handle.saveToStream(os);
	switch (_fetype) {
		case FE_OPEN:
			_fname.saveToStream(os);
			break;
		case FE_CLOSE:
			break;
		case FE_READ:
			break;
		case FE_WRITE:
			break;
		default:	
			break;
	}
}


void FileEvent::readFromStream(std::istream &is) {
	is.read(reinterpret_cast<char*>(&_fetype), sizeof(_fetype));
	_handle.readFromStream(is);
	switch (_fetype) {
		case FE_OPEN:
			_fname.readFromStream(is);
			break;
		case FE_CLOSE:
			break;
		case FE_READ:
			break;
		case FE_WRITE:
			break;
		default:	
			THROW(platform::SerializationException, "unexpected type of FileEvent");
	}
}


void FileEvent::writeDebugInfo(std::ostream &os) const {
	os << "FileEvent: type=";
	switch (_fetype) {
		case FE_OPEN:
			os << "OPEN: name=";
			_fname.writeDebugInfo(os);
			break;
		case FE_CLOSE:
			os << "CLOSE";
			break;
		case FE_READ:
			os << "READ";
			break;
		case FE_WRITE:
			os << "WRITE";
			break;
		default:
			os << "<Unknown>";
	}
	os << " handle:";
	_handle.writeDebugInfo(os);
	os << '\n';
}


}  // end namespace